package com.beiye.drivertransport.adapter;

import android.content.Context;
import android.widget.TextView;

import com.beiye.drivertransport.R;
import com.beiye.drivertransport.bean.IntegralRecordBean;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by ky on 2018/9/27.
 */

public class IntegralRecrodApt extends ListBaseAdapter<IntegralRecordBean.RowsBean> {

    protected Context context = null;


    public IntegralRecrodApt(Context context){
        super(context);
        this.context = context;
    }

    @Override
    public int getLayoutId() {
        return  R.layout.integral_record_item;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder,final int position) {
        TextView tv_title = holder.getView(R.id.tv_title);
        TextView tv_date = holder.getView(R.id.tv_date);
        TextView tv_num = holder.getView(R.id.tv_num);
        String piName = getDataList().get(position).getPiName();
        int spointType = getDataList().get(position).getSpointType();
        int asMark = getDataList().get(position).getAsMark();
        int pointNo = getDataList().get(position).getPointNo();

        if(asMark==1)//增加
        {
            if(piName==null)
            {
                tv_title.setText("");
                tv_num.setText("+"+pointNo+"积分");
            }else{
                tv_title.setText(piName);
                tv_num.setText("+"+pointNo+"积分");
            }

        }else if(asMark==2){//减少
            if(spointType==1)
            {

                tv_title.setText("购买商品");
                tv_num.setText("-"+pointNo+"积分");
            }else{
                tv_title.setText("未定义");
                tv_num.setText("-"+pointNo+"积分");
            }
        }

        long creationDate = getDataList().get(position).getCreationDate();
        if (creationDate > 0) {
            Date date = new Date(creationDate);
            String creation="";
            try {
                //yyyy表示年MM表示月dd表示日
                //yyyy-MM-dd是日期的格式，比如2015-12-12如果你要得到2015年12月12日就换成yyyy年MM月dd日
                SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日  HH:mm");
                //进行格式化
                creation = sdf.format(date);
                tv_date.setText(creation);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            tv_date.setText("");

        }

    }






}